﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;
using Infusion.Silverlight.Controls;

namespace SilverlightRibbon
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            HtmlPage.Document.AttachEvent("oncontextmenu", this.OnContextMenu);

            //Infusion.Silverlight.Controls.OpenOfficeXML.WordProcessing.Document doc = new Infusion.Silverlight.Controls.OpenOfficeXML.WordProcessing.Document();
            //doc.CreateNew();
        }

        private void OnContextMenu(object sender, HtmlEventArgs e)
        {
            Point clickPoint = new Point(e.OffsetX, e.OffsetY);
            List<UIElement> itemsHit = (List<UIElement>)VisualTreeHelper.FindElementsInHostCoordinates(clickPoint, this);

            if (itemsHit.Contains(Doc))
            {
                e.PreventDefault();
                RibbonCtrl.ShowMenu("MenuContext", clickPoint, true);
            }
        }

        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            RibbonCtrl.Width = e.NewSize.Width;
            Doc.Width = e.NewSize.Width;
            Doc.Height = e.NewSize.Height - 140;
        }

        private void RibbonButton_ButtonClick(object sender, MouseButtonEventArgs e)
        {
        }

        private void RibbonButton_ButtonClick_Copy(object sender, MouseButtonEventArgs e)
        {
            Clipboard.SetText(string.Format("Silverlight Ribbon Control: {0}", DateTime.Now.ToString()));
        }

        private void RibbonButton_ButtonClick_Paste(object sender, MouseButtonEventArgs e)
        {
            Doc.Pages[0].tbxPageText.Text = Clipboard.GetText();
        }
    }
}
